package opl.entities;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import opl.utilities.FileHelper;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class Team {
	
	private static List<Team> lstTeams;

	private String Name;
	private String Captian;
	private String ViceCaptian;
	private String Owner;
	private List<String> Members;
	private float Rating;

	public String getOwner() {
		return Owner;
	}

	public void setOwner(String owner) {
		Owner = owner;
	}

	public String getName() {
		return Name;
	}

	public void setName(String name) {
		Name = name;
	}

	public String getCaptian() {
		return Captian;
	}

	public void setCaptian(String captian) {
		Captian = captian;
	}

	public String getViceCaptian() {
		return ViceCaptian;
	}

	public void setViceCaptian(String viceCaptian) {
		ViceCaptian = viceCaptian;
	}

	public List<String> getMembers() {
		return Members;
	}

	public void setMembers(List<String> members) {
		Members = members;
	}

	public float getRating() {
		return Rating;
	}

	public void setRating(float rating) {
		Rating = rating;
	}
	
	public static List<Team> getTeams(Context context){
		if (lstTeams==null){
			lstTeams = new ArrayList<Team>();
			try {
				String jsonTeams = FileHelper.ReadFileAsString("teams.txt", context);
				Type collectionType = new TypeToken<Collection<Team>>() {
				}.getType();
				Collection<Team> teams = new Gson().fromJson(jsonTeams,
						collectionType);

				lstTeams.addAll(teams);
			} catch (Exception e) {
				lstTeams = null;
				e.printStackTrace();
			}
		}
		return lstTeams;
	}
}
